﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aho.PathEditor.Business.Base;
using System.ComponentModel;
using System.IO;

namespace Aho.PathEditor.Business.Entities
{
    public class PathEntity: Entity, INotifyPropertyChanged
    {
        public PathEntity()
        {
            this.AccessScope = PathScope.Undefined;
        }

        public PathEntity(string directory, PathScope scope)
        {
            this.Directory = directory;
            this.AccessScope = scope;
        }

        private string _Directory;
        public string Directory
        {
            get
            {
                this.m_PropErrors.Remove("Directory");
                if (!System.IO.Directory.Exists(_Directory))
                {
                    this.Error = "Error";
                    this.m_PropErrors["Directory"] = "Directory";
                }
                else
                {
                    this.m_PropErrors.Remove("Directory");
                }
                return _Directory;
            }
            set
            {
                _Directory = value;
                FireChangedEvent("Directory");
            }
        }
        private PathScope _AccessScope;
        public PathScope AccessScope
        {
            get
            {
                if (_AccessScope == PathScope.Undefined)
                {
                    this.Error = "Error";
                    this.m_PropErrors["AccessScope"] = "Set the Access-Scope";
                }
                    else
                {
                    this.m_PropErrors.Remove("AccessScope");
                }
                return _AccessScope;
            }
            set
            {
                
                _AccessScope = value;
                FireChangedEvent("PathScope");
            }
        }

        public override string ToString()
        {
            return string.Format("{0}: {1}", base.ToString(),this.Directory);
        }

        #region INotifyPropertyChanged Members

        private void FireChangedEvent(string propertyName)
        {
            if (this.PropertyChanged!=null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
